//
//  TIMModifyGroupNameVC.m
//  Demo_sdk
//
//  Created by Deli Xia on 2018/7/9.
//  Copyright © 2018年 Deli Xia. All rights reserved.
//

#import "TIMModifyGroupNameVC.h"
#import "TIMDemoMacro.h"
#import "ProgressHUD.h"

#import "TIMStorageModel.h"
#import "TIMStorageManager.h"
#import "TIMApi.h"

@interface TIMModifyGroupNameVC ()<UITextFieldDelegate>
@property (nonatomic, strong) TIMGroupInfo *groupInfo;
@property (nonatomic, strong) UITextField *textfield;
@end

@implementation TIMModifyGroupNameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = DefaultBackGroundColor;
    self.title = @"修改群名";
    [self.view addSubview:self.textfield];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - TextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [TIMApi operateGroupWithGroupId:self.groupID operateUserId:nil MsgOperation:TIMOperateGroupTypeModifyGroupName groupMembers:nil GroupName:[self.textfield.text dataUsingEncoding:NSUTF8StringEncoding] completion:^(NSError *error) {
        if (!error) {
             NSLog(@"-------------xiadeli-------------修改群名成功ok");
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        } else {
            [ProgressHUD showHudTipStr:@"修改群名失败"];
        }
    }];
    self.textfield.text = nil;
    [self.view becomeFirstResponder];
    return YES;
}

- (UITextField *)textfield {
    if (!_textfield) {
        _textfield = [[UITextField alloc] initWithFrame:CGRectMake(0, 90, self.view.frame.size.width, 40)];
        _textfield.borderStyle = UITextBorderStyleRoundedRect;
        _textfield.backgroundColor = UIColor.whiteColor;
        _textfield.delegate = self;
        _textfield.placeholder = @"修改群名";
    }
    return _textfield;
}

@end
